﻿using System.Threading.Tasks;
using System.Windows.Controls;

namespace WPFTestSolution.Pages.Controls.RangeBases {
    
    /**
     * https://www.bilibili.com/video/BV1bV411A7Eq?p=46
     * 046-ProgressBar进度条(: RangeBase: Control)
     * https://www.wpfsoft.com/2023/08/30/1596.html
     */
    public partial class _46_ProgressBar_Page : Page {
        public _46_ProgressBar_Page() {
            InitializeComponent();
            this.Title = "046-ProgressBar进度条(: RangeBase: Control)";
            
            Loaded += (s, e) => {
                //增加了一个子线程
                Task.Factory.StartNew(() => {
                    for (int i = 0; i <= 100; i++) {
                        //Dispatcher类，将访问UI线程的代码成成一个匿名函数，交给Dispatcher去执行
                        Dispatcher.Invoke(() => {
                            _TextBlock.Text = $"{i}%";
                            ProgressBar0.Value = i;
                        });
                        
                        Task.Delay(25).Wait();
                    }
                });
            };
        }
    }
}